package com.zzf.concurrent.example.design.pattern.thread.local.context;

import com.zzf.concurrent.example.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author GaoFeng2017
 * @date 2019/9/8 14:47
 */
@Slf4j
public class OrderService implements Runnable {

    private PostageDao postageDao = new PostageDao();
    private UserDao userDao = new UserDao();

    @Override
    public void run() {
        OrderContext orderContext = new OrderContext();
        orderContext.setFormData(new Object());
        OrderContextUtil.setContext(orderContext);
        String threadName = Thread.currentThread().getName();
        log.info("{} -> begin query userInfo...", threadName);
        // String s = userDao.queryUserInfo((int) (Math.random() * 20) + 1, orderContext);
        String s = userDao.queryUserInfo((int) (Math.random() * 20) + 1);
        log.info("{} ->  user info is {}", threadName,s);
        TimeUtil.sleep((long) (Math.random() * 2000));
        log.info("{} -> begin query postage...", threadName);
        // int postageAmount = postageDao.queryPostage(orderContext);
        int postageAmount = postageDao.queryPostage();
        log.info("{} -> postage is {}", threadName, postageAmount);
    }
}
